package com.yswee.mallnavi.parser;

import org.json.JSONArray;
import org.json.JSONObject;

import com.yswee.mallnavi.context.ContextConstant;

public abstract class BaseJsonParser<T> extends com.yswee.framework.data.parser.BaseJsonParser<T> {

	public static final String TAG_RESULT_CODE = "code";
	public static final String TAG_RESULT_MSG = "msg";
	public static final String TAG_RESULT_DATA = "data";

	protected JSONObject readCode(String jsonOrigin) {
		JSONObject jo = asJSONObject(jsonOrigin);
		JSONObject joresult = null;
		mCode = getString(jo, TAG_RESULT_CODE);
		mMessage = getString(jo, TAG_RESULT_MSG);
		if(mCode != null) { 
			if(mCode.equals(ContextConstant.RESPONSECODE_SUCC)) {
				joresult = jo.optJSONObject(TAG_RESULT_DATA);
				mIsOk = true;
			}
		} else {
			mIsOk = false;
		}
		return joresult;
	}
	
	protected JSONArray readListCode(String jsonOrigin) {
		JSONObject jo = asJSONObject(jsonOrigin);
		JSONArray ja = null;
		mCode = getString(jo, TAG_RESULT_CODE);
		mMessage = getString(jo, TAG_RESULT_MSG);
		if(mCode != null) {
			if(mCode.equals(ContextConstant.RESPONSECODE_SUCC)) {
				ja = jo.optJSONArray(TAG_RESULT_DATA);
				mIsOk = true;
			} else {
				mIsOk = false;
			}
		} else {
			mIsOk = false;
		}
		return ja;
	}
	
}
